// Copyright (c) 2022, hzmes and contributors
// For license information, please see license.txt

frappe.ui.form.on('SRM AlterMold', {
	refresh: function(frm) {
        if ( frappe.user_roles.includes('SRM Purchase') && frm.doc.workflow_state == 'Hand In') {
            frm.add_custom_button(__('费用确认'), () => {
                frappe.prompt('Amount', ({ value }) => {frm.set_value('amount_of_money', value); frm.refresh_field('amount_of_money'); frm.save();})
            });
        };
		
		frm.add_custom_button(__('返回公共查询'), () => {
			frappe.set_route('query-report', 'SRM AlterMold Rep', {})
		}).addClass('btn-primary');

	},

	before_workflow_action: (frm) => {
		if ( frm.doc.workflow_state ==="Hand In" && frm.selected_workflow_action === "Approve" && frm.doc.amount_of_money == 0) {
			console.log(frm.selected_workflow_action);
            frappe.throw("金额为0不允许审核");
		}
	},
});
